<?php
/**
 * 世界杯竞猜 通用模块
 */
namespace WorldCupLast\Controller;
use Common\Controller\CommonController;
class IndexController extends CommonController{

    const AppID     =   'wxb2dfa5282782f280';
    const AppSecret =   'a814e9599f2da97118888ebcb447d3f8';

    /**
     * 存放模板消息
     */
    public function send()
    {
        $app_data       =   array('wxb26efa19cb837835'=>'86cd81876b2c203de94f6b17e6f144e9','wxb2dfa5282782f280'=>'a814e9599f2da97118888ebcb447d3f8');
        $form_id        =   I('post.form_id','','htmlspecialchars');
        $touser         =   I('post.touser','','htmlspecialchars');
        $appid          =  	I('post.appid','','htmlspecialchars');
        $form_type      =   1;
        $template_id    =   1;
        $date           =   date('Y-m-d');
        $app            =   'worldcuplast';         //区分大小写
        $table          =   'common_template_send';

        if (! empty($form_id) && ! empty($appid))
        {
            $secret         =   $app_data[$appid];
            $app_appid      =   $appid;

            $insert_data = array(
                'app'=>$app,
                'app_appid'=>$app_appid,
                'appid'=>$appid,
                'template_id'=>$template_id,
                'page'=>'pages/index/index',
                'form_id'=>$form_id,
                'form_type'=>$form_type,
                'status'=>'-1',
                'add_time'=>time(),
                'secret'=>$secret,
                'createtime'=>$date,
                'touser'=>$touser
            );

            M($table)->add($insert_data);
        }

    }

    /**
     * 广告
     */
    public function advertising()
    {
        $appid              =  	I('post.appid','','htmlspecialchars');
        $data               =   array();
        if (! empty($appid))
        {
            $where              =   array();
            $where['isshow']    =   1;
            $where['app_appid'] =   $appid;
            $data = M('common_ad')->where($where)->select();

            if(! empty($data))
            {
                foreach ($data as $key=>$val)
                {
                    $data[$key]['logo'] = $this->url.$data[$key]['logo'];
                }
            }
        }

        $this->returnData($data,$msg='ok',$code=200);
    }

    /**
     * 跟多好玩
     */
    public function more()
    {
        $data['appid']  =   'wx6b1c7907c5733fc9';
        $data['path']   =   '/pages/index/index';
        $this->returnData($data,$msg='ok',$code=200);
    }

}